/*
 * Copyright (c) gitee.com/jiandong001.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { YogaNative } from './YogaNative';
import { YogaConfigNAPIBase } from './YogaConfigNAPIBase';
/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

export class YogaConfigNAPIFinalizer extends YogaConfigNAPIBase {
  public constructor() {
    super();
  }

  // @Override -> ts4.3 override
  // TODO should use ark's gc related functionality
  protected finalize(): void | never {
    try {
      this.freeNatives();
    } finally {
      //this.finalize();
    }
   }

  public freeNatives(): void {
    if (this.mNativePointer != 0) {
      let nativePointer = this.mNativePointer;
      this.mNativePointer = 0;
      YogaNative.napi_YGConfigFreeNAPI(nativePointer);
    }
  }
}
